package solution.node;

import common.Node;
import common.util.NodeUtil;

/**
 * @author : wenchao.long
 * @date : Created in 2021/7/15 13:37 周四
 * @description : N叉树的最大深度
 */
public class MaxDepthSolution {

    public int maxDepth(Node root) {
        return dfs(root);
    }

    private int dfs(Node node) {
        if (node == null || node.children == null) {
            return 0;
        }
        int result = 1;
        for (Node child : node.children) {
            result = Math.max(result, 1 + dfs(child));
        }
        return result;
    }

    public static void main(String[] args) {
        Node root = NodeUtil.create(1, null, 2, 3, 4, 5, null, null, null, null, 6, 7, null, null, 8, null, null, 9, 10, null, null, null, null, 11, null, null, 12, null, null, 13, null, null, null, null, 14, null);
        int dept = new MaxDepthSolution().maxDepth(root);
        System.out.println(dept);
    }

}
